package org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.domain.AbstractAggregateRoot;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity.event.AddActivityEvent;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity.event.DeleteActivityEvent;
import org.zachary.prosocialbehaviorservice.domain.aggregate_model.activity.event.ModifyActivityEvent;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name="activity")
@Data
public class Activity extends AbstractAggregateRoot<Activity> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    private String title;
    private String logo;
    private String introduce;
    private String content;
    private String sponsor;
    private String address;

    @Transient
    private List<ActivityItem> items = new ArrayList<>();
    protected Activity() {}

    private Activity(String title, String logo, String introduce, String content, String sponsor, String address) {
        this.title = title;
        this.logo = logo;
        this.introduce = introduce;
        this.content = content;
        this.sponsor = sponsor;
        this.address = address;
    }
    public static Activity buildForAdd(String title, String logo, String introduce, String content, String sponsor, String address){
        return new Activity(title, logo, introduce, content, sponsor, address);
    }

    public void loadItems(List<ActivityItem> loadedItems) {
        this.items.clear();
        this.items.addAll(loadedItems);
    }

    public List<ActivityItem> getItems() {
        return Collections.unmodifiableList(items);
    }

    public void addItem(ActivityItem item) {
        this.items.add(item);
    }


    public void addActivity(){
        registerEvent(new AddActivityEvent(this));
    }
    public void removeActivity(){
        registerEvent(new AddActivityEvent((this)));
    }

    public void add() {
        registerEvent((new AddActivityEvent(this)));
    }

    public void delete() {

    }

    public void modify() {
        registerEvent((new ModifyActivityEvent(this)));
    }

}
